<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>getMathValue</title>
</head>

<body>
    <div>打开浏览器控制台查看结果</div>
    <script>
        const getMathValue = (...args) => {
            args = args.reduce((res, item) => {
                const n = Number(item);
                if (typeof item === 'number' && !isNaN(n)) res.push(n);
                return res;
            }, []);
            // 创建一个对象返回结果
            var result = {
                sum: 0,
                max: 0,
                min: 0,
                average: 0
            },
                len = args.length;
            // 暂定第一个参数就是最大值与最小值
            result['max'] = args[0];
            result['min'] = args[0];
            for (let i = 0; i < len; i++) {
                // 求和
                result['sum'] += args[i];
                // 最大值
                if (args[i] > result['max']) result['max'] = args[i];
                // 最小值
                if (args[i] < result['min']) result['min'] = args[i];
            }
            // 平均数
            result['average'] = result['sum'] / len;
            return result;
        };
        console.log(getMathValue(1, 2, 3, null)); // { sum:6,max:3,min:1,average:2}
    </script>
</body>

</html>